package com.xfcycle.zebrabikegp.util;

import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;

/**
 * 检查用户权限列表 工具类
 * Created by xFcycle on 2017/5/26.
 */
public class PermissionsCheckerUtil {

    private Context mContext;

    public PermissionsCheckerUtil(Context context){
        mContext = context;
    }

    /**
     * 判断权限集合
     * @param permissions 需要判断的权限集合
     * @return 返回的判断结果 true 为拒绝 false 为授权
     */
    public boolean judgePermissionListDenied(String[] permissions){
        for (String permission:permissions){
            if(judgePermissionListDenied(permission)){
                return true;
            }
        }
        return false;
    }

    /**
     * 单独判断当前权限是否拥有
     * @param permission 需要判断的权限
     * @return 该权限是否已拥有 true 为拒绝 false 为授权
     */
    private boolean judgePermissionListDenied(String permission){
        return ContextCompat.checkSelfPermission(mContext,permission) == PackageManager.PERMISSION_DENIED;
    }
}
